package orkomet;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.ModelMaker;


import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
// <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
// #[regen=yes,id=DCE.195A8346-3ADB-9619-0C36-B6C0D3A48610]
// </editor-fold> 
public class RDFEngine {
    private static ModelMaker maker = ModelFactory.createModelRDBMaker(DerbyDAL.getConnection());

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.D5CE76BC-0767-3242-99D9-BDAD41D079F5]
    // </editor-fold> 
    public static Model GetModel() {
        Model orkometModel = maker.createModel("Orkomet");
        if (orkometModel.isEmpty()) {
            orkometModel.removeAll();
            InputStream is = null;
            try {
                is = RDFEngine.class.getResourceAsStream("/MediaLibrarySchema.owl");                
                orkometModel.read(is, "");
                is.close();
                is = RDFEngine.class.getResourceAsStream("/MediaLibrary.owl");                
                orkometModel.read(is, "");
                is.close();
            } catch (FileNotFoundException ex) {
                Logger.getLogger(RDFEngine.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(RDFEngine.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                try {
                       if(is!=null)
                           is.close();
                } catch (IOException ex) {
                    Logger.getLogger(RDFEngine.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        return orkometModel;
    }
    
    public static void InitLog()
    {
        Model m=GetModel();
        String modelsize=String.valueOf( m.size());
        String fmts=java.util.ResourceBundle.getBundle("orkomet/logprops").getString("checkModel");
        Logger.getLogger(RDFEngine.class.getName()).log(Level.INFO,String.format(fmts,"Ork",modelsize) );
    }
}

